﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DatabaseCompare.Model;
using DatabaseCompare.Service.Compare;

namespace DatabaseCompare.ServiceImpl.Compare
{
    public class TriggerCompare :
        CompareAbleCompare<TriggerInfo>,
        ICompareAbleCompare<TriggerInfo, TriggerCompareResult>
    {

        /// <summary>
        /// 两个触发器比较.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public TriggerCompareResult Compare(TriggerInfo left, TriggerInfo right)
        {
            // 比较结果.
            TriggerCompareResult result = new TriggerCompareResult();

            // 设置比较参数.
            result.Left = left;
            result.Right = right;

            // 首先简单作非空的判断.
            result.CompareResult = base.CommonCompare(left, right);

            if (result.CompareResult == CommonCompareResult.FullSame)
            {
                // 左右都不为空
                // 需要详细比较.

                // 是否被禁用
                if (left.IsDisable != right.IsDisable)
                {
                    result.CompareResult = CommonCompareResult.Difference;
                    result.IsDisableDifference = true;
                }

                // // 是否被禁用
                if (left.IsInsteadOfTrigger != right.IsInsteadOfTrigger)
                {
                    result.CompareResult = CommonCompareResult.Difference;
                    result.IsInsteadOfTriggerDifference = true;
                }

                // 创建触发器的语句
                if (left.CreateSQL != right.CreateSQL)
                {
                    result.CompareResult = CommonCompareResult.Difference;
                    result.CreateTriggerSQLDifference = true;
                }
            }

            // 返回.
            return result;
        }
    }
}
